package cn.zhentao.controller;

import cn.zhentao.pojo.Teacher;
import cn.zhentao.pojo.User;
import cn.zhentao.service.TeacherService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Map;

//RestController：Controller+ResponseBody
@RestController
@RequestMapping("tea")
public class TeacherController {
    @Autowired
    private TeacherService service;

    @RequestMapping("findAll")
    public List<Teacher> findAll(){
        List<Teacher> list = service.findAll();
        return list;
    }

    @RequestMapping("findByName")
    public List<Teacher> findByName(String tName){
        return service.findByName(tName);
    }

    @RequestMapping("delTeacher")
    public int delTeacher(int tId){
        return service.delTeacher(tId);
    }

    @RequestMapping("login")
    public int login(@RequestBody Teacher tea){
        System.out.println(tea);
        Teacher t1 = service.login(tea.getTname(),tea.getPassword());
        System.out.println("t1:"+t1);
        if(t1!=null){
            return 1;
        }else{
            return 0;
        }
    }
    @RequestMapping("getUser")
    public int getUser(@RequestBody Teacher tea){
        System.out.println(tea);
        return 0;
    }
}
